package mathive.client.panels;

import mathive.client.PanelHandler;
import mathive.client.UserHandler;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ResultsPanel {

	private VerticalPanel mainPanel = new VerticalPanel();
	private HTML title = new HTML("<h1>Results</h1>");
	private String gameTitle;
	private String gameId= null;
	private int result = 0;
	private Button retryButton = new Button();
	private Button homeButton = new Button();
	
	public ResultsPanel(){
		retryButton.setText("Try another game");
		homeButton.setText("Back to Home");
		
		// Listen for mouse events on the retry button.
		retryButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				PanelHandler.showGames();
			}
		});

		// Listen for mouse events on the home button.
		homeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				PanelHandler.showHome();
			}
		});
		
	}
	
	public Widget getPanel(){
		return mainPanel;
	}
	
	public void showResult(String gTitle, String gameId, int result){

		mainPanel.clear();
		
		this.gameTitle = gTitle;
		this.gameId = gameId;
		this.result = result;
		
		mainPanel.add(title);
		mainPanel.add(new HTML("<p>Congratulations! You scored " + result + 
				" points on " + gameTitle + "!</p>"));
		mainPanel.add(retryButton);
//		mainPanel.add(homeButton);

		UserHandler.singleton.addScore(result);
	}
	
}
